<?php
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/db/BaseDAO.php';
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/util/plog/classes/plog.php';

class PublishUserDAO extends BaseDAO {
	
	public function __construct() {
		parent::__construct ();
		$this->log = Plog::factory ( __FILE__ );
	}
	
	public function updateUserNotify($account, $notifyBudgetUpdate, $notifyAdApprovedNot, $notifyAdModify, $notifyAdApproved, $notifyPayComplete) {
		
		$sql = "update user set  
		  			 notifyBudgetUpdate=$notifyBudgetUpdate,
		  			 notifyAdApprovedNot=$notifyAdApprovedNot,
		  			 notifyAdModify=$notifyAdModify,
		  			 notifyAdApproved=$notifyAdApproved,
		  			 notifyPayComplete=$notifyPayComplete 
		  			 where account = '$account'";
		
		$this->log->debug ( "更新使用者設定:" . $sql );
		$result = mysql_query ( $sql );
		$this->log->debug ( "更新使用者設定結果:" . $result );
		return $result;
	}
	
	public function getManagerUser($account, $password) {
	
	}
	
	public function getUser($account) {
		$sql = "select u.BankCode,u.BankName,u.BranchOfBank,u.BankAccount,u.Name , u.Account ,sum(PayMoney) PayMoney,s.Status from user u left join paytouser s on u.Account=s.Account where u.Account='$account' group by u.Account,Status";
//		echo $sql;
		$result = @mysql_query ( $sql );
		$items = $this::toArray ( $result );
		return $items;
	}
	
	public function queryTargetAccountMember($account, $name) {
		

		
		$sql = "select account,name,status,IFNULL(settle,0) settle  from (select u.account, u.name, u.status from user u  where u.proxyAccount ='$account') a left join  (select account paytouserAccount, sum(PayMoney) settle from paytouser where status=0) s on  a.account=s.paytouserAccount";
		if (null != $name) {
			$sql = $sql . " and u.name like '%$name%'";
		}
		$sql=$sql." group by account";
//		echo $sql;
		$result = @mysql_query ( $sql );
		$items = $this::toArray ( $result );
		return $items;
	}
	public function queryManagerAccount() {
		$sql = "select u.account, u.name, u.status, s.count, s.settle 
				from user u join settledetail s on u.account=s.account where u.proxyAccount = '$account' ";
		if (null != $name) {
			$sql = $sql . "name like '%$name%'";
		}
		//		echo $sql;
		$result = @mysql_query ( $sql );
		$items = $this::toArray ( $result );
		return $items;
	}
	
	/*
	 * 更新使用者的銀行資訊
	 */
	public function updateUserBankInfo($account, $bankCode,
	 $bankName, $branchOfBank, $bankAccount) {
		$sql = "update user set  
		  			 BankCode='$bankCode',
		  			 BankName='$bankName',
		  			 BranchOfBank='$branchOfBank',
		  			 BankAccount='$bankAccount'
		  			 where account = '$account'";
		
//		$this->log->debug ( "更新使用者設定:" . $sql );
//		echo $sql;
		$result = mysql_query ( $sql );
//		$this->log->debug ( "更新使用者設定結果:" . $result );
		return $result;
//		return $sql;
	}
}

?>